<?php
namespace Cyfy\Modules\RelatedLinks\Forms;
use \Cyfy\Message;
use \Cyfy\Modules\Forms;
use \Cyfy\Modules\RelatedLinks\Module;

/**
 * Creates a new QuickLink.
 */
class Create extends Forms\Form
{
    public $path;
    
	function structure()
	{		
		$this -> permission("RelatedLinks", "create and edit links");
		
		$i = new Forms\TextBox("name", self :: t(110));
		$i -> required = true;
		$i -> maxLength = 100;
		$this -> addItem($i);
		
        $i = new Forms\Select("type", self :: t(120));
		$i -> required = true;
        $i -> data = Module :: $types;
		$this -> addItem($i);
        
        $i = new Forms\Hidden("path");
        if($this -> path){
            $i -> value = $this -> path;
        }
		$this -> addItem($i);
        
        
		$i = new Forms\TextBox("link", self :: t(130));
		$i -> required = true;

		$i -> maxLength = 255;
		$this -> addItem($i);
		
	
		
		$b = new Forms\Button(self :: t(140), Forms\Button::OK);
		$this -> addButton($b);
		
		$this -> onSubmit = "Blocks.reload('RelatedLinks', 'links');";
    }

  
	function submit()
	{  
        
		if(\dibi :: query("INSERT INTO [:cyfy:RelatedLinks] %v", $this -> getAll()))
        {
			\Cyfy\Message :: set(self :: t(201, array($this->get("name"))));
            return true;     
		}	
		
        \Cyfy\Message :: set(self :: t(211, array($this->get("name"))), \Cyfy\Message::ERROR);
	}	
}